package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlCourseModules entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlCourseModules
 * @author MyEclipse Persistence Tools
 */

public class MdlCourseModulesDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlCourseModulesDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String MODULE = "module";
	public static final String INSTANCE = "instance";
	public static final String SECTION = "section";
	public static final String IDNUMBER = "idnumber";
	public static final String ADDED = "added";
	public static final String SCORE = "score";
	public static final String INDENT = "indent";
	public static final String VISIBLE = "visible";
	public static final String VISIBLEOLD = "visibleold";
	public static final String GROUPMODE = "groupmode";
	public static final String GROUPINGID = "groupingid";
	public static final String GROUPMEMBERSONLY = "groupmembersonly";
	public static final String COMPLETION = "completion";
	public static final String COMPLETIONGRADEITEMNUMBER = "completiongradeitemnumber";
	public static final String COMPLETIONVIEW = "completionview";
	public static final String COMPLETIONEXPECTED = "completionexpected";
	public static final String AVAILABLEFROM = "availablefrom";
	public static final String AVAILABLEUNTIL = "availableuntil";
	public static final String SHOWAVAILABILITY = "showavailability";
	public static final String SHOWDESCRIPTION = "showdescription";

	public void save(MdlCourseModules transientInstance) {
		Transaction trx = getSession().beginTransaction();
		log.debug("saving MdlCourseModules instance");
		try {
			getSession().save(transientInstance);
			trx.commit();
			trx=null;
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			trx=null;
			throw re;
		}
	}

	public void delete(MdlCourseModules persistentInstance) {
		log.debug("deleting MdlCourseModules instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlCourseModules findById(java.lang.Long id) {
		log.debug("getting MdlCourseModules instance with id: " + id);
		try {
			MdlCourseModules instance = (MdlCourseModules) getSession().get(
					"idv.loveloser.dao.MdlCourseModules", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlCourseModules instance) {
		log.debug("finding MdlCourseModules instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlCourseModules")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlCourseModules instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlCourseModules as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByModule(Object module) {
		return findByProperty(MODULE, module);
	}

	public List findByInstance(Object instance) {
		return findByProperty(INSTANCE, instance);
	}

	public List findBySection(Object section) {
		return findByProperty(SECTION, section);
	}

	public List findByIdnumber(Object idnumber) {
		return findByProperty(IDNUMBER, idnumber);
	}

	public List findByAdded(Object added) {
		return findByProperty(ADDED, added);
	}

	public List findByScore(Object score) {
		return findByProperty(SCORE, score);
	}

	public List findByIndent(Object indent) {
		return findByProperty(INDENT, indent);
	}

	public List findByVisible(Object visible) {
		return findByProperty(VISIBLE, visible);
	}

	public List findByVisibleold(Object visibleold) {
		return findByProperty(VISIBLEOLD, visibleold);
	}

	public List findByGroupmode(Object groupmode) {
		return findByProperty(GROUPMODE, groupmode);
	}

	public List findByGroupingid(Object groupingid) {
		return findByProperty(GROUPINGID, groupingid);
	}

	public List findByGroupmembersonly(Object groupmembersonly) {
		return findByProperty(GROUPMEMBERSONLY, groupmembersonly);
	}

	public List findByCompletion(Object completion) {
		return findByProperty(COMPLETION, completion);
	}

	public List findByCompletiongradeitemnumber(Object completiongradeitemnumber) {
		return findByProperty(COMPLETIONGRADEITEMNUMBER,
				completiongradeitemnumber);
	}

	public List findByCompletionview(Object completionview) {
		return findByProperty(COMPLETIONVIEW, completionview);
	}

	public List findByCompletionexpected(Object completionexpected) {
		return findByProperty(COMPLETIONEXPECTED, completionexpected);
	}

	public List findByAvailablefrom(Object availablefrom) {
		return findByProperty(AVAILABLEFROM, availablefrom);
	}

	public List findByAvailableuntil(Object availableuntil) {
		return findByProperty(AVAILABLEUNTIL, availableuntil);
	}

	public List findByShowavailability(Object showavailability) {
		return findByProperty(SHOWAVAILABILITY, showavailability);
	}

	public List findByShowdescription(Object showdescription) {
		return findByProperty(SHOWDESCRIPTION, showdescription);
	}

	public List findAll() {
		log.debug("finding all MdlCourseModules instances");
		try {
			String queryString = "from MdlCourseModules";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlCourseModules merge(MdlCourseModules detachedInstance) {
		Transaction trx = getSession().beginTransaction();
		log.debug("merging MdlCourseModules instance");
		try {
			MdlCourseModules result = (MdlCourseModules) getSession().merge(
					detachedInstance);
			trx.commit();
			log.debug("merge successful");
			trx=null;
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			trx=null;
			throw re;
		}
	}

	public void attachDirty(MdlCourseModules instance) {
		log.debug("attaching dirty MdlCourseModules instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlCourseModules instance) {
		log.debug("attaching clean MdlCourseModules instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}